#ifndef _FEAT_DATA_H_
#define _FEAT_DATA_H_
#include <string.h>
#pragma pack(push)
#pragma pack(1)
typedef struct 
{
	unsigned int iid; // imageid
    unsigned int he; 
    unsigned int x:12;
    unsigned int y:12;
    unsigned int bundleID:8;
} pattern_feat_data_t;

typedef struct
{
	unsigned int iid; // imageid
    unsigned int he; 
    unsigned int x:12;
    unsigned int y:12;
    unsigned int bundleID:8;
} sift_feat_data_t;

typedef struct
{
	unsigned int iid; // imageid
    unsigned char data[1560]; // new
} shape_feat_data_t;

typedef struct
{
	unsigned int iid; // imageid
    unsigned char data[552]; // new
} topo_feat_data_t;


typedef struct
{
	unsigned int iid; // imageid
    unsigned int data[32];
} color_feat_data_t;

typedef struct global_feat
{
	unsigned int iid;
	unsigned char data[598];
}global_feat_data_t ;

typedef struct local_feat
{
	unsigned int iid;
	unsigned char data[8];
} local_feat_data_t;
#pragma pack(pop)

class base_feature
{
public:
	base_feature() {};
	virtual ~base_feature() {};
	void set_iid(unsigned int id)
	{
		*(reinterpret_cast<unsigned int*>(get_data_buf())) = id;
	};
	virtual base_feature *clone() = 0;
	virtual unsigned int get_iid() const { return *(reinterpret_cast<const unsigned int*>(get_data_buf())); }
	virtual int get_length() const = 0;
	virtual void *get_data_buf() = 0;
	virtual const void *get_data_buf() const = 0;
	
};

template <class feat_struct> 
class feature: public base_feature
{
	feat_struct data;
public:
	int get_length() const  { return sizeof(data); }
	void *get_data_buf() { return reinterpret_cast<void *>(&data); }
	const void *get_data_buf() const { return reinterpret_cast<const void *>(&data); }
	base_feature *clone() {
		feature<feat_struct> *obj = new feature<feat_struct>;
		memcpy(reinterpret_cast<void *>(&obj->data), get_data_buf(), get_length());
		return obj;
	}
};

#endif
